﻿using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Serilog;

namespace Identification.Importer.Server
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        private static IWebHost BuildWebHost(string[] args)
        {
            var hostingconfiguration = new ConfigurationBuilder()
                .AddJsonFile("hosting.json", false, true)
                .AddCommandLine(args).Build();

            return WebHost.CreateDefaultBuilder(args)
                .UseKestrel()
                .ConfigureServices(services => services.AddAutofac())
                .UseConfiguration(hostingconfiguration)
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    config.AddJsonFile("appsettings.json", false, true);
                    config.AddEnvironmentVariables();
                })
                .UseSerilog(
                    (context, configuration) => { configuration.ReadFrom.Configuration(context.Configuration); })
                .UseStartup<Startup>()
                .Build();
        }
    }
}